import { message, Modal } from 'ant-design-vue'
import { createVNode } from 'vue'
import { QuestionCircleOutlined } from '@ant-design/icons-vue'
import { checkStatus } from '../utils/http/axios/checkStatus'

/***
 * @description 表格多选删除
 * @param ref 绑定子组件
 * @param del 删除接口
 * @param ids 选择数组
 */
export const deleteMultiple = async (ref, del, ids: Array<any>) => {
  await del({ ids: ids, force: 0 }, { isShowMessage: false }).then(res => {
    if (-5 == Number(res.code)) {
      Modal.confirm({
        title: '提示',
        icon: createVNode(QuestionCircleOutlined),
        content: '策略已在模板中使用，是否解除所有绑定并删除',
        onOk: async () => {
          await del({ ids: ids, force: 1 }, { isShowMessage: true })
          ref.value.refreshTableData()
        }
      })
    } else {
      if (0 == Number(res.code)) {
        message.success(res.message)
      } else {
        checkStatus(res.code, res.message, true)
      }
      ref.value.refreshTableData()
      return Promise.resolve()
    }
  })
}
